package com.zprmb.udzt.adapter;

import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zprmb.udzt.R;
import com.zprmb.udzt.bean.ExBean;
import com.zprmb.udzt.util.BitmapUtils;
import com.zprmb.udzt.util.Regular;

public class Ex_infoAdapter extends BaseAdapter {
	private Context context;
	private List<ExBean> list;
	private String title;
	

	public Ex_infoAdapter(Context context, List<ExBean> list, String title) {
		super();
		this.context = context;
		this.list = list;
		this.title = title;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@SuppressLint("NewApi")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		Help h=null;
		if(convertView==null){
			h=new Help();
			convertView=LayoutInflater.from(context).inflate(R.layout.ex_gold_item3, null);
			h.tv_activity=(TextView)convertView.findViewById(R.id.tv_channel);
			h.tv_amount=(TextView)convertView.findViewById(R.id.amount);
			h.tv_date=(TextView)convertView.findViewById(R.id.tv_date);
		    h.iv_state=(ImageView)convertView.findViewById(R.id.btn_invest);
			h.tv_term=(TextView)convertView.findViewById(R.id.shouyi_term);
			h.li_bg=(RelativeLayout)convertView.findViewById(R.id.li_bg);
			convertView.setTag(h);
			
		}else{
			h=(Help) convertView.getTag();
		}
		h.li_bg.setBackground(new BitmapDrawable(BitmapUtils.readBitMap(context,R.drawable.bjj)));
		h.tv_activity.setText(list.get(position).getExperienceName());
		h.tv_amount.setText("¥"+list.get(position).getExperienceAmount());
		
		if(title.equals("已使用")){
			
//			if(list.get(position).getState().equals("UN_USE")){
//				h.iv_state.setImageResource(R.drawable.);
//			}else{
//				
//			}
		if(list.get(position).getState().equals("NOT_ARRIVAL")){
			h.iv_state.setImageResource(R.drawable.tzz);
			h.tv_term.setText("收益期限:"+list.get(position).getExperienceDays()+"天");
			h.tv_date.setText("投资时间:  "+Regular.getMilliToDate(list.get(position).getCountRateTime()));
		}else{
			h.iv_state.setImageResource(R.drawable.yhk);
			h.tv_term.setText("已获收益:"+list.get(position).getReceivedInterest());
			h.tv_date.setText("收益到账时间:  "+Regular.getMilliToDate(list.get(position).getActualArriveTime()));
		}
			
		}
		else{
			h.iv_state.setImageResource(R.drawable.ygq);
			
			h.tv_term.setText("收益期限:"+list.get(position).getExperienceDays()+"天");
			h.tv_date.setText("有效期:  "+Regular.getMilliToDate(list.get(position).getStartTime())+"至"+Regular.getMilliToDate(list.get(position).getEndTime()));
		}
		
		return convertView;
	}
	class Help{
		private TextView tv_activity,tv_amount,tv_term,tv_date;
		private ImageView iv_state;
		private RelativeLayout li_bg;
		
	}

}
